package com.ruibang.glass.quality.component.job;

import com.ruibang.glass.quality.constant.Constants;
import com.ruibang.glass.quality.domain.req.DiscardDefectReq;
import com.ruibang.glass.quality.service.TotalEquDataService;
import com.teaming.cloud.framework2.elastic.job3.annotation.ElasticJobScheduler;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-01-30  09:21
 * @Description: TODO:热端判废缺陷（每天）
 * @Version: 1.0
 */
@Slf4j
@ElasticJobScheduler(cron = "2 20 7 * * ?", name = "EverydayHotScrapJudgmentDefectTask", shardingItemParameters = "0=0", jobParameters = "parameter")
//@ElasticJobScheduler(cron = "2 * * * * ?", name = "EverydayHotScrapJudgmentDefectTask")
@Component
public class EverydayHotScrapJudgmentDefectTask implements SimpleJob {

    @Autowired
    private TotalEquDataService totalEquDataService;

    @Override
    public void execute(ShardingContext shardingContext) {
        log.error("------------热端判废缺陷（每天）开始----------------");
        LocalDate now = LocalDate.now();
        String startDate = now.minusDays(Constants.DEFECT_DEFAULT_QUERY_DAYS).format(DateTimeFormatter.ISO_LOCAL_DATE);
        String endDate = now.format(DateTimeFormatter.ISO_LOCAL_DATE);
        DiscardDefectReq defectReq = new DiscardDefectReq();
        defectReq.setStartDate(startDate);
        defectReq.setEndDate(endDate);
        defectReq.setCheckMachineCode("CM2");
        //检查机类型0:冷端，1:热端
        defectReq.setCheckMachineType(Constants.ONE_STR);
        //检查机类型0:半成品，1:成品
        defectReq.setIsFinished(Constants.ZERO_STR);
        //调用
        totalEquDataService.importEverydayDiscardDefect(defectReq);
        log.error("------------热端判废缺陷（每天）结束----------------");
    }
}
